package com.hellohoper.cloud.starter.swagger;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.ResponseEntity;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * Created by hk on 12/13/16.
 */
@Configuration
@ConditionalOnClass({Docket.class})
public class SwaggerConfig {

    @Bean
    public Docket appApiDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("Api")
                .genericModelSubstitutes(ResponseEntity.class)
                .useDefaultResponseMessages(false)
                .forCodeGeneration(false)
                .pathMapping("/")
                .select()
                .paths(PathSelectors.regex("/api/.*"))
                .build()
                .apiInfo(new ApiInfo("Swagger Api", null, null, null, new Contact(null, null, null), null, null));
    }

    @Bean
    public Docket springBootDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("Spring Boot")
                .genericModelSubstitutes(ResponseEntity.class)
                .useDefaultResponseMessages(false)
                .forCodeGeneration(false)
                .pathMapping("/")
                .select()
                .paths(PathSelectors.regex("/error.*|/beans.*|/autoconfig.*|/beans.*|/configprops.*|/dump.*" +
                        "|/info.*|/mappings.*|/trace.*|/env.*|/metrics.*|/health.*"))
                .build()
                .apiInfo(new ApiInfo("Swagger Api", null, null, null, new Contact(null, null, null), null, null));
    }
}
